package com.roy.sms.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 加密工具类,使用MD5或SHA加密字符串
 * 
 * @author rzpeng
 * 
 */
public class EncryptUtil {

	/**
	 * 使用MD5算法加密,返回16进制的字符串
	 * 
	 * @param s
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public static String getMD5(String s) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("MD5");
		md.update(s.getBytes());
		return new BigInteger(md.digest()).toString(16);
	}

	/**
	 * 使用SHA算法加密,返回16进制的字符串
	 * 
	 * @param s
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public static String getSHA(String s) throws NoSuchAlgorithmException {
		MessageDigest md = MessageDigest.getInstance("SHA");
		md.update(s.getBytes());
		return new BigInteger(md.digest()).toString(16);
	}

}
